<?php
// +----------------------------------------------------------------------
//            -------------------------
//           /   / ----------------\  \
//          /   /             \  \
//         /   /              /  /
//        /   /    /-------------- /  /
//       /   /    /-------------------\  \
//      /   /                   \  \
//     /   /                     \  \
//    /   /                      /  /
//   /   /      /----------------------- /  /
//  /-----/      /---------------------------/
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://baimifan.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: Sage 2016/7/22  8:54
// +----------------------------------------------------------------------
namespace Admin\Controller;
use Common\Model\OrderBookView;
use Common\Model\ApplyView;
use Service\ServiceContainer;

class OrderPushController extends BaseController{
    function __construct() {
        parent::__construct();
        layout(false);
        $this->di=new ServiceContainer();
        $this->OrderBookView=new OrderBookView();
        $this->ApplyView=new ApplyView();
    }

    function index(){
        $this->display();
    }

    function main(){
        layout(false);
        $this->display();
    }

    function getOrderRent(){
        $idx=I('post.order_id')?I('post.order_id'):'0';//已显示的当前页面
        $where=[
            'order_id'=>['gt',$idx],
            'type'=>'1',            //借书
            'state_order'=>'1',     //未发货
            'is_online'=>'0',       //线上
            'is_print'=>'0'         //是否打印
        ];
        $field='order_id,card_id,create_time';
        $d=$this->OrderBookView->where($where)->field($field)->limit('0,5')->order('order_id desc')->group('order_id')->select();
        $j=[
            'status'=>'success',
            'data'=>$d
        ];
        echo echoJson($j);
    }
    function getDetailRent(){
        $order_id=I('post.order_id')?I('post.order_id'):'0';//已显示的当前页面
        $where=[
            'order_id'=>$order_id,
        ];
        $field='order_id,card_id,address,book_id,isbn,spbs,tm,sm,press,create_time';
        $d=$this->OrderBookView->where($where)->field($field)->select();
        $j=[
            'status'=>'success',
            'data'=>$d
        ];
        echo echoJson($j);
    }

    function getOrderBuy(){
        $idx=I('post.order_id')?I('post.order_id'):'0';//已显示的当前页面
        $where=[
            'order_id'=>['gt',$idx],
            'type'=>'0',            //购买
            'state_order'=>'1',     //未发货
            'is_online'=>'0',       //线上
            'is_print'=>'0'         //是否打印
        ];
        $field='order_id,card_id,create_time';
        $d=$this->OrderBookView->where($where)->field($field)->limit('0,5')->order('order_id desc')->group('order_id')->select();
        $j=[
            'status'=>'success',
            'data'=>$d
        ];
        echo echoJson($j);
    }

    function getDetailBuy(){
        $order_id=I('post.order_id')?I('post.order_id'):'0';//已显示的当前页面
        $where=[
            'order_id'=>$order_id,
        ];
        $field='order_id,card_id,address,book_id,isbn,spbs,tm,sm,press,create_time';
        $d=$this->OrderBookView->where($where)->field($field)->select();
        $j=[
            'status'=>'success',
            'data'=>$d
        ];
        echo echoJson($j);
    }

    function getOrderApply(){
        $idx=I('post.apply_id')?I('post.apply_id'):'0';//已显示的当前页面
        $where=[
            'apply_id'=>['gt',$idx],
            'pay_status'=>'1',                          //已付款
            'apply_end'=>['gt',date('Y-m-d H:i:s')],    //活动时间内
            'apply_start'=>['lt',date('Y-m-d H:i:s')],
            'is_print'=>'0',        //是否打印
            'way'=>'wechat'         //微信支付
        ];
        $field='apply_id,title,create_time,card_id';
        $d=$this->ApplyView->where($where)->field($field)->limit('0,5')->order('apply_id desc')->group('apply_id')->select();
//        var_dump($d);exit;
        $j=[
            'status'=>'success',
            'data'=>$d
        ];
        echo echoJson($j);
    }

    function getDetailApply(){
        $apply_id=I('post.apply_id')?I('post.apply_id'):'0';//已显示的当前页面
        $where=[
            'apply_id'=>$apply_id,
        ];
        $field='apply_id,card_id,title,create_time,title,price_apply,price_material,activity_start,activity_end,contactor';
        $d=$this->ApplyView->where($where)->field($field)->find();
        $j=[
            'status'=>'success',
            'data'=>$d
        ];
        echo echoJson($j);
    }
    
    function isPrint(){
        $order_id = I("post.order_id");
        $type = I("post.type");
        switch ($type){
            case 1:
                $res = M("order_book")->where(["order_id"=>$order_id])->setField("is_print",1);
                break;
            case 2:
                $res = M("activity_apply")->where(["apply_id"=>$order_id])->setField("is_print",1);
                break;
        }
        var_dump($res);

    }
}